/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package z.h.w.jar.kit.code.ci;

import java.awt.Image;
import java.awt.Point;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;

/**
 *
 * @author EnzoZhong
 */
public class Sub implements BeSub {

        private BufferedImage bufferedImage;
        private Point point;

        /**
         * 
         * @param bufferedImage
         * @param x
         * @param y
         */
        public Sub( BufferedImage bufferedImage, Integer x, Integer y ) {
                this.bufferedImage = bufferedImage;
                this.point = new Point( x, y );
        }

        /**
         * 
         * @param url
         * @param x
         * @param y
         */
        public Sub( URL url, Integer x, Integer y ) {
                Image image = null;
                try {
                        image = ImageIO.read( url );
                } catch (IOException ex) {
                        Logger.getLogger( Sub.class.getName() ).log( Level.SEVERE, null, ex );
                }

                Integer width = image.getWidth( null );
                Integer height = image.getHeight( null );
                bufferedImage = new BufferedImage( width, height, BufferedImage.TYPE_INT_RGB );
                bufferedImage.getGraphics().drawImage( image, 0, 0, null );
                this.point = new Point( x, y );
        }

        /**
         * 
         * @param file
         * @param x
         * @param y
         */
        public Sub( File file, Integer x, Integer y ) {
                Image image = null;
                try {
                        image = ImageIO.read( file );
                } catch (IOException ex) {
                        Logger.getLogger( Sub.class.getName() ).log( Level.SEVERE, null, ex );
                }
                Integer width = image.getWidth( null );
                Integer height = image.getHeight( null );
                bufferedImage = new BufferedImage( width, height, BufferedImage.TYPE_INT_RGB );
                bufferedImage.getGraphics().drawImage( image, 0, 0, null );
                this.point = new Point( x, y );
        }

        /**
         * 
         * @return
         */
        public BufferedImage getBufferedImage() {
                return bufferedImage;
        }

        /**
         * 
         * @return
         */
        public Point getPoint() {
                return point;
        }
}
